<%--
  - Copyright 2011 Angel Sanadinov
  -
  - This file is part of VBox WMI.
  -
  - VBox WMI is free software: you can redistribute it and/or modify
  - it under the terms of the GNU General Public License as published by
  - the Free Software Foundation, either version 3 of the License, or
  - (at your option) any later version.
  -
  - VBox WMI is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU General Public License for more details.
  -
  - You should have received a copy of the GNU General Public License
  - along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
  --%>

<%@page import="Utilities.Functions"%>
<%@page import="Managers.Utilities.User"%>
<%@page import="Utilities.ParameterNames"%>
<%@page import="Utilities.ParameterNames.Service"%>
<%@page import="Beans.Responses.DataRetrievalResponse"%>
<%@page import="Utilities.Constants.SendingRequestResult"%>
<%@page import="Utilities.UIFunctions"%>
<%@page import="Beans.Requests.DataRetrieval.SnapshotsDataRetrievalRequest"%>
<%@page import="Beans.Responses.DataRetrievalComponents.MachineSnapshotDataComponent"%>
<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@taglib uri="/WEB-INF/tlds/pagePrintingTags.tld" prefix="p"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="jstlc"%>
<%
    //retrieves user data from the session
    User userSessionData = (User)session.getAttribute(ParameterNames.SESSION_USER_OBJECT);

    //data retrieval request and response objects
    SnapshotsDataRetrievalRequest dataRequest = null;
    DataRetrievalResponse<MachineSnapshotDataComponent> data = null;

    //attempts to retrieve the machine UUID
    String machineId = request.getParameter("id");
    if(Functions.isUUIDValid(machineId))
    {
        //builds the data request
        dataRequest = new SnapshotsDataRetrievalRequest(userSessionData.getUserData().getUserId(), userSessionData.getCurrentServerId(), machineId);

        //attempts to send the request and retrieves the response
        if(UIFunctions.sendServiceRequest(request, response, dataRequest, Service.DATA_RETRIEVAL) == SendingRequestResult.OK)
            data = (DataRetrievalResponse<MachineSnapshotDataComponent>)UIFunctions.retrieveServiceResponse(request, Service.DATA_RETRIEVAL);
        else
            ;
    }
    else
        ;
%>
<p:printPageHeader pageName="Snapshots Management" pageId="pageMachines" userSessionData="<%= userSessionData %>"/>
    Snapshots for machine <%= machineId %> / <a class="operationsLink" href="machines.jsp?id=<%= machineId %>">View</a><br>
    <p:printSnapshot snapshot="<%= data.getResource() %>" rootLevelString="|-" subLevelString="-" />
    <a class="creationLink" href="noJavaScript.jsp" onclick="return changePopupVisibility('formCreateSnapshot');">Create Snapshot</a>
    <form id="formCreateSnapshot" class="resourceCreationElement" action="manage_machine.jsp?action=3&amp;id=<%= machineId %>&amp;operation=1" method="post">
        <table>
            <tr><td>Create Snapshot:</td></tr>
            <tr><td>Snapshot Name:</td><td><input type="text" name="create.snapshot.name"></td></tr>
            <tr><td>Snapshot Description:</td><td><input type="text" name="create.snapshot.description"></td></tr>
            <tr><td><input type="submit" value="Create"></td></tr>
        </table>
    </form>
<p:printPageFooter/>